package com.dd.cloud.user.service.chknowl.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.common.interceptor.UserInterceptor;
import com.dd.cloud.common.vo.LoginInfo;
import com.dd.cloud.user.entity.chknowl.ChkonwDoctorReadSetting;
import com.dd.cloud.user.mapper.chknowl.ChkonwDoctorReadSettingMapper;
import com.dd.cloud.user.req.chknowl.ChnowlReadSettingReq;
import com.dd.cloud.user.service.chknowl.IChkonwDoctorReadSettingService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 阅读器书籍设置 服务实现类
 * </p>
 *
 * @author czg
 * @since 2023-10-30
 */
@Service
public class ChkonwDoctorReadSettingServiceImpl extends ServiceImpl<ChkonwDoctorReadSettingMapper, ChkonwDoctorReadSetting> implements IChkonwDoctorReadSettingService {

    @Override
    public void addDoctorReadSetting(ChnowlReadSettingReq chnowlReadSettingReq) {
        LambdaQueryWrapper<ChkonwDoctorReadSetting> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ChkonwDoctorReadSetting::getDoctorId, chnowlReadSettingReq.getDoctorId());
        ChkonwDoctorReadSetting chkonwDoctorReadSetting = this.getOne(wrapper);
        if (chkonwDoctorReadSetting == null) {
            ChkonwDoctorReadSetting readSetting = new ChkonwDoctorReadSetting();
            readSetting.setDoctorId(chnowlReadSettingReq.getDoctorId())
                    .setTheme(chnowlReadSettingReq.getTheme())
                    .setFontType(chnowlReadSettingReq.getFontType())
                    .setFontSize(chnowlReadSettingReq.getFontSize())
                    .setCreateDate(LocalDateTime.now());
            this.save(readSetting);
        } else {
            chkonwDoctorReadSetting
                    .setCreateDate(LocalDateTime.now())
                    .setTheme(chnowlReadSettingReq.getTheme())
                    .setFontType(chnowlReadSettingReq.getFontType())
                    .setFontSize(chnowlReadSettingReq.getFontSize());
            this.updateById(chkonwDoctorReadSetting);
        }
    }

    @Override
    public ChkonwDoctorReadSetting queryDoctorReadSetting(Integer doctorId) {
        LambdaQueryWrapper<ChkonwDoctorReadSetting> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ChkonwDoctorReadSetting::getDoctorId, doctorId);
        return this.getOne(wrapper);
    }
}
